package com.paranoidvulture.javaEngine.Utilities;

import java.awt.Graphics2D;
import java.awt.Image;
import java.io.InputStream;

import javax.imageio.ImageIO;

/* This is the Control Base
 * It inherits from IControl
 * This is all the basic functions that are universal to a control
 * You can override them or leave them how they are depending on the control
 * Most of them deal with the life cycle, positioning, and image of the control
 */

public abstract class ControlBase implements IControl{

	//variables
	private float posX;
	private float posY;
	private int width;
	private int height;
	private String imageString;
	private Image image;
	private String name;
	private boolean active;
	
	public ControlBase(){
	}
	
	@Override
	public void setActive(boolean active){
		this.active = active;
	}
	
	@Override
	public boolean getActive(){
		return this.active;
	}
	
	@Override
	public float getPosX() {
		return this.posX;
	}

	@Override
	public float getPosY() {
		return this.posY;
	}

	@Override
	public int getWidth() {
		return this.width;
	}

	@Override
	public int getHeight() {
		return this.height;
	}

	@Override
	public void setPosX(float x) {
		this.posX = x;	
	}

	@Override
	public void setPosY(float y) {
		this.posY = y;
	}
	
	public void setPosition(float x, float y) {
		setPosX(x);
		setPosY(y);
	}
	
	public void setPosition(int x, int y) {
		setPosX(x);
		setPosY(y);
	}
	
	@Override
	public void setWidth(int width) {
		this.width = width;
	}

	@Override
	public void setHeight(int height) {
		if (height < 32){
			height = 32;
		}
		this.height = height;
	}

	@Override
	public String getName() {
		return this.name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public Image getPicture() {
		return this.image;
	}

	@Override
	public void setImage(String image) {
		try{
			this.imageString = image;
			//ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
			InputStream input = ClassLoader.getSystemResourceAsStream(this.imageString);
			this.image = ImageIO.read(input);
		}catch (Exception ex){}
	}

	@Override
	public void init() {
		//set the image of the control
		
		
	}

	@Override
	public void draw(Graphics2D g) {
		// draw shit
		
	}

	public void update(long timePassed) {
		// TODO Auto-generated method stub
		
	}

}
